package com.railway.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.railway.bean.User;
import com.railway.bean.Vo;
import com.railway.dao.UserDao;
import com.railway.dao.impl.UserDaoImpl;
import com.railway.service.AdminService;
import com.railway.service.impl.AdminServiceImpl;
import com.railway.util.JSONUtil;

/**
 * Servlet implementation class UserShowServlet
 */
@WebServlet("/UserShowServlet.do")
public class UserShowServlet extends HttpServlet {
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		int pageNum,pageSize;
		if(request.getParameter("page") == null) {
			pageNum = 1;
		}else {
			pageNum = Integer.parseInt(request.getParameter("page"));
		}
		

		if(request.getParameter("limit") == null) {
			pageSize = 10;
		}else {
			pageSize = Integer.parseInt(request.getParameter("limit"));
		}
		AdminService as = new AdminServiceImpl();
		Vo<User> vo = new Vo(); 
		UserDao ud = new UserDaoImpl();
		List<User> list= ud.selectUser(pageNum, pageSize);
		vo.setCode(0);
		vo.setMsg("success");
		vo.setData(list);
		vo.setCount(ud.selectCountUser());
		JSONUtil.responJSOn(response, vo);
	}

}
